<cfparam name="resetFilters" default="false">
<cfparam name="showStats" default="false" />
<cfset isFiltered = false />
<cfset queryParams = StructNew() />

<!--- Program years --->
<cfif NOT IsDefined("client.gds.programYears") or resetFilters>
	<cfset client.gds.programYears = request.currentProgramYear>
<cfelseif IsDefined("filterProgramYears")>
	<cfset client.gds.programYears = filterProgramYears>
</cfif>
<cfif client.gds.programYears neq request.currentProgramYear>
	<cfset isFiltered = true />
	<cfset queryParams.programYears = client.gds.programYears />
<cfelse>
	<cfset queryParams.programYears = request.currentProgramYear />
</cfif>
<!--- Match Criteria --->
<cfif NOT IsDefined("client.gds.Match_Criteria") or resetFilters>
	<cfset client.gds.Match_Criteria = "1">
<cfelseif IsDefined("filterMatchCriteria")>
	<cfset client.gds.Match_Criteria = filterMatchCriteria>
</cfif>
<cfif client.gds.Match_Criteria neq "All">
	<cfset isFiltered = true />
	<cfset queryParams.Match_Criteria = client.gds.Match_Criteria />
</cfif>
<!--- Organizations --->
<cfif NOT IsDefined("client.gds.organizationIDs") or resetFilters>
	<cfset client.gds.organizationIDs = "All">
<cfelseif IsDefined("filterOrganizationIDs")>
	<cfset client.gds.organizationIDs = filterOrganizationIDs>
</cfif>
<cfif client.gds.organizationIDs neq "All">
	<cfset isFiltered = true />
	<cfset queryParams.organizationIDs = client.gds.organizationIDs />
	<cfset filterRegionIDs = "All" />
</cfif>
<!--- Regions --->
<cfif IsUserInRole("Super User")>
	<cfif NOT IsDefined("client.gds.regionIDs") or resetFilters>
		<cfset client.gds.regionIDs = "All">
	<cfelseif IsDefined("filterRegionIDs")>
		<cfset client.gds.regionIDs = filterRegionIDs>
	</cfif>
<cfelseif IsUserInRole("Regional Admin")>
	<cfset client.gds.regionIDs = request.authUser.regionID>
</cfif>
<cfif client.gds.regionIDs neq "All">
	<cfset isFiltered = true />
	<cfset queryParams.regionIDs = client.gds.regionIDs />
</cfif>
<!--- Proposal Value --->
<cfif NOT IsDefined("client.gds.proposalValue") or resetFilters>
	<cfset client.gds.proposalValue = "Unmatch">
<cfelseif IsDefined("filterScoreCategory")>
	<cfset client.gds.proposalValue = filterScoreCategory>
</cfif>
<cfif client.gds.proposalValue neq "All">
	<cfset isFiltered = true />
	<!--- <cfset queryParams.proposalValue = client.gds.proposalValue /> --->
</cfif>

<cfwddx action="cfml2wddx" input="#queryParams#" output="client.gds.queryParamsWDDX" />

<cfscript>
	base = new assets.calgrants.com.Base();
	organizationGateway = new assets.calgrants.com.gateway.OrganizationGateway();
	organizations = organizationGateway.query(regionIDs = IIf(IsUserInRole("Regional Admin"), request.authUser.regionID, ""), Organization_ID = IIf(IsUserInRole("Organizer") OR IsUserInRole("Site Contact"), request.authUser.organizationID, ""));
	storedProcedureGateway = new assets.calgrants.com.gateway.StoredProcedureGateway();
	regions = storedProcedureGateway.call("getDistinctRegions");
	gdsGateway = new assets.calgrants.com.gateway.GDSGateway();
	gds = gdsGateway.query(argumentCollection = queryParams);
</cfscript>

<h3>GDS<cfif isFiltered> <small><em>filtered</em></small></cfif></h3>

<cfoutput>
 
	<div class="row-fluid" style="margin-bottom: 10px;">
		<div class="span12">
			<a id="filterLink" href="##" class="btn" onclick="toggleFilter('filter')">Show filters</a>
			<span class="pull-right"><strong>Count:</strong> #gds.RecordCount#</span>
		</div>
	</div>
	
	<cfform name="gdsForm" id="gdsForm" action="#script_name#" method="post">
		<cfinput type="hidden" name="view" value="#view#">
		
		<div id="filter" class="alert alert-info alert-block" style="display: none;">
			<h4>Filters</h4>
			<table cellpadding="6">
				<tr valign="top">
					<td>
						<label>Program Year</label>
						<cfselect name="filterProgramYears" size="1" multiple="false" required="yes" message="Program Year filter is required" style="width: 150px;">
							<cfloop index="y" from="2012" to="#ListFirst(application.currentProgramYear, '-')#">
								<cfset py = "#y#-" & y+1>
								<option value="#py#"<cfif client.gds.programYears eq py> selected</cfif>>#py#</option>
							</cfloop>
						</cfselect>
					</td>
					<cfif IsUserInRole("Super User")>
						<td>
							<label>Region</label>
							<cfselect name="filterRegionIDs" size="7" multiple="true" required="yes" message="Region filter is required" style="width: 150px;">
								<option value="All"<cfif client.gds.regionIDs eq "All"> selected</cfif>>All</option>
								<cfloop query="regions">
									<option value="#Region_ID#"<cfif ListFind(client.gds.regionIDs, Region_ID)> selected</cfif>>#Region_ID#</option>
								</cfloop>
							</cfselect>
						</td>
					</cfif>
					<td>
						<label>Organizations</label>
						<cfselect name="filterOrganizationIDs" size="7" multiple="true" required="yes" message="Organizations filter is required" style="width: auto;">
							<option value="All"<cfif client.gds.organizationIDs eq "All"> selected</cfif>>All</option>
							<cfloop query="organizations">
								<option value="#Organization_ID#"<cfif ListFind(client.gds.organizationIDs, Organization_ID)> selected</cfif>>#Organization# - #City#</option>
							</cfloop>
						</cfselect>
					</td>
					<td>
						<label>Match Criteria Level</label>
						<cfselect name="filterMatchCriteria" size="1" required="yes" message="Match Criteria Level filter is required" style="width: 150px;">
							<!--- <option value="All"<cfif client.gds.matchCriteria eq "All"> selected</cfif>>All</option> --->
							<cfloop index="matchCriteria" from="1" to="20">
								<option value="#matchCriteria#"<cfif ListFind(client.gds.Match_Criteria, matchCriteria)> selected</cfif>>#matchCriteria#</option>
							</cfloop>
						</cfselect>
					</td>
					<td>
						<label>Score Category</label>
						<cfselect name="filterScoreCategory" size="1" required="yes" message="Score Category filter is required" style="width: 150px;">
							<!--- <option value="All"<cfif client.gds.proposalValue eq "All"> selected</cfif>>All</option> --->
							<cfloop list="Match,Review,Unmatch" index="proposalValue">
								<option value="#proposalValue#"<cfif ListFind(client.gds.proposalValue, proposalValue)> selected</cfif>>#proposalValue#</option>
							</cfloop>
						</cfselect>
					</td>
				</tr>
				<tr>
					<td colspan="5">
						<button type="submit" class="btn btn-info">Apply</button> <a href="#script_name#?view=#view#&resetFilters=true" class="btn btn-info">Clear</a>
					</td>
				</tr>
			</table>
		</div>
	</cfform>

</cfoutput>
<style>
	div.rec-box {
		min-height: 200px;
	}
	span.highlighted {
		background-color: green;
		color: white;
		
	}
	span.hl {
		background-color: white;
		color: grey;
	}
	table.score-table td {
		width: 100%;
	}
	table.stat-table td, table.stat-table th {
		font-size: 0.7em;
		padding: 2px 4px;
	}
</style>

<cfif gds.RecordCount gt 0>

	<script type="text/javascript">
		var unmatchGDS = function(gdsId) {
			$.ajax({
				type: "GET",
				url: "/assets/calgrants/com/API.cfc?method=destroy",
				data: $.param({objType: "GDS", GDS_ID: gdsId}),
				success: function(response) {
					$("#gdsMatch_" + gdsId).slideUp("slow");
				},
				error: function(jqXHR, textStatus, errorThrown) {
					alert("Something went wrong. Please contact the developer");
				}
			});
		}
		var confirmUnmatch = function(gdsId) {
			if (confirm("Are you sure you want to remove this match\?")) {
				unmatchGDS(gdsId);
			}
		}
	</script>
	<cfscript>
		displayedCount = 0;
	</cfscript>
	<div class="container-fluid">
		<cfloop query="gds">
			<cfscript>
				// GDS
				gdsStruct = structNew();
				//gdsStruct.Student_ID = Student_ID;
				gdsStruct.First_Name = Replace(REReplace(UCase(Trim(First_Name)), "[^A-Z\ \-\']", "", "all"), "  ", " ", "all");
				gdsStruct.Last_Name = Replace(REReplace(UCase(Trim(Last_Name)), "[^A-Z\ \-\']", "", "all"), "  ", " ", "all");
				//gdsStruct.Full_Name = gdsStruct.First_Name & " " & gdsStruct.Last_Name;
				gdsStruct.Address = Replace(REReplace(UCase(Trim(Address)), "[^A-Z0-9\ ]", "", "all"), "  ", " ", "all");
				gdsStruct.City = Replace(REReplace(UCase(Trim(City)), "[^A-Z\ ]", "", "all"), "  ", " ", "all");
				gdsStruct.Zip_Code = Left(REReplace(Trim(Zip_Code), "[^0-9]", "", "all"), 5);
				//gdsStruct.Full_Address = gdsStruct.Address & " " & gdsStruct.City & " " & gdsStruct.Zip_Code;
				gdsStruct.Email = REReplace(UCase(Trim(Email)), "[^A-Z0-9\@\.\_\-]", "", "all");
				gdsStruct.SSN = Right(REReplace(Trim(SSN), "[^0-9]", "", "all"), 4);
				// Student
				studentStruct = structNew();
				//studentStruct.Student_ID = Student_ID;
				studentStruct.First_Name = Replace(REReplace(UCase(Trim(Student_First_Name)), "[^A-Z\ \-\']", "", "all"), "  ", " ", "all");
				studentStruct.Last_Name = Replace(REReplace(UCase(Trim(Student_Last_Name)), "[^A-Z\ \-\']", "", "all"), "  ", " ", "all");
				//studentStruct.Full_Name = studentStruct.First_Name & " " & studentStruct.Last_Name;
				studentStruct.Address = Replace(REReplace(UCase(Trim(Student_Address)), "[^A-Z0-9\ ]", "", "all"), "  ", " ", "all");
				studentStruct.City = Replace(REReplace(UCase(Trim(Student_City)), "[^A-Z\ ]", "", "all"), "  ", " ", "all");
				studentStruct.Zip_Code = Left(REReplace(Trim(Student_Zip_Code), "[^0-9]", "", "all"), 5);
				//studentStruct.Full_Address = studentStruct.Address & " " & studentStruct.City & " " & studentStruct.Zip_Code;
				studentStruct.Email = REReplace(UCase(Trim(Student_Email)), "[^A-Z0-9\@\.\_\-]", "", "all");
				studentStruct.SSN = Right(REReplace(Trim(Student_SSN), "[^0-9]", "", "all"), 4);
				if (isDate(DOB)) {
					gdsStruct.DOB = DateFormat(DOB, "mm/dd/yyyy");
				} else {
					gdsStruct.DOB = "";
				}
				if (isDate(Student_DOB)) {
					studentStruct.DOB = DateFormat(Student_DOB, "mm/dd/yyyy");
				} else {
					studentStruct.DOB = "";
				}
				gdsStruct.Phone = REReplace(Trim(Phone), "[^0-9]", "", "all");
				usePhone = base.pickPhone(Phone, Student_Phone1, Student_Phone2);
				if (usePhone eq "phone1") {
					studentStruct.Phone = REReplace(Trim(Student_Phone1), "[^0-9]", "", "all");
				} else {
					studentStruct.Phone = REReplace(Trim(Student_Phone2), "[^0-9]", "", "all");
				}
				// Do the comparison! struct1 is GDS, struct2 is Student
				//compareResult = base.compareStructs(gdsStruct, studentStruct);
				compareResult = base.scoreStructs(gdsStruct, studentStruct);
				// create pointer variables for brevity of code
				result = compareResult.result;
				gds = compareResult.struct1;
				student = compareResult.struct2;
				config = compareResult.config;
				/* 
					GDS has one phone, Student has two.
					The comparison created properties for both combinations: GDS.Phone vs Student.Phone1 and GDS.Phone vs Student.Phone2.
					Keep the best match score, eliminate the other from scoring.
					
					- if Phone2 score is equal to or better than Phone1, create a Phone property and set it to result for Phone2
					- otherwise create Phone property and set it to result of Phone1
					- delete Phone1 and Phone2 properties (in all 4 structs) so they aren't scored down the line
				*/
				try {
					perfectDiscount = compareResult.perfect * .025;
					bonusDiscount = compareResult.bonus * .025;
					totalBonus = perfectDiscount + bonusDiscount;
					matchThreshold = .7 - totalBonus;
					unmatchThreshold = .5;
				}
				catch(any err) {
					writeDump(err);
					writeDump(var = compareResult, expand = "no");
				}
			</cfscript>
			<cfif 	(client.gds.proposalValue eq "Match" and compareResult.score gte matchThreshold)
					or (client.gds.proposalValue eq "Unmatch" and compareResult.score lte unmatchThreshold)
					or (client.gds.proposalValue eq "Review" and compareResult.score gt unmatchThreshold and compareResult.score lt matchThreshold)>
				<cfoutput>
					<div id="gdsMatch_#GDS_ID#" class="row">
						<div class="span2">
							<h4>Student</h4>
							<div class="rec-box">
								<span class="highlighted">
									#result.first_name.string2#<br />
									#result.last_name.string2#<br />
									#result.address.string2#<br />
									#result.city.string2#<br />
									#result.zip_code.string2#<br />
									#result.email.string2#<br />
									#result.phone.string2#<br />
									#result.dob.string2#<br />
									#result.ssn.string2#
								</span>
							</div>
							<p>Student ID: #Student_ID#</p>
						</div>
						<div class="span2">
							<h4>GDS</h4>
							<div class="rec-box">
								<span class="highlighted">
									#result.first_name.string1#<br />
									#result.last_name.string1#<br />
									#result.address.string1#<br />
									#result.city.string1#<br />
									#result.zip_code.string1#<br />
									#result.email.string1#<br />
									#result.phone.string1#<br />
									#result.dob.string1#<br />
									#result.ssn.string1#
								</span>
							</div>
							<p>GDS ID: #GDS_ID#</p>
						</div>
						<div class="span4">
							<table class="table table-bordered score-table">
								<tr>
									<th>Similarity</th>
									<td>#DecimalFormat(compareResult.similarity)#</td>
								</tr>
								<tr>
									<th>Commonality</th>
									<td>#DecimalFormat(compareResult.commonality)#</td>
								<tr>
									<th>Continuity</th>
									<td>#DecimalFormat(compareResult.continuity)#</td>
								</tr>
								<tr>
									<th>Score</th>
									<td>#DecimalFormat(compareResult.score)#</td>
								</tr>
								<tr>
									<th>Bonus/Penalty</th>
									<td>+#totalBonus#</td>
								</tr>
								<tr>
									<th nowrap>Auto Verification</th>
									<td>#client.gds.proposalValue#</td>
								</tr>
								<tr>
									<td colspan="2">
										<cfif compareResult.score gte matchThreshold>
											<a href="##" class="btn btn-danger btn-block" onclick="confirmUnmatch(#GDS_ID#); return false;">Unmatch</a>
										<cfelseif compareResult.score lte unmatchThreshold>
											<a href="##" class="btn btn-success btn-block" onclick="unmatchGDS(#GDS_ID#); return false;">Unmatch</a>
										<cfelse>
											<a href="##" class="btn btn-warning btn-block" onclick="confirmUnmatch(#GDS_ID#); return false;">Unmatch</a>
										</cfif>
									</td>
								</tr>
							</table>
						</div>
						<div class="span4">
							<table class="table table-bordered table-striped table-condensed stat-table">
								<thead>
									<tr>
										<th width="40%">Field</th>
										<th width="15%">Similarity</th>
										<th width="15%">Commonality</th>
										<th width="15%">Continuity</th>
										<th width="15%">Score</th>
									</tr>
								</thead>
								<tbody>
									<cfset fields = StructKeyList(result) />
									<cfset fields = ListSort(fields, "TextNoCase") />
									<cfloop index="prop" list="#fields#">
										<tr>
											<td>#prop#</td>
											<td>#DecimalFormat(result[prop].similarity)#</td>
											<td>#DecimalFormat(result[prop].commonality)#</td>
											<td>#DecimalFormat(result[prop].continuity)#</td>
											<td>#DecimalFormat(result[prop].score)#</td>
										</tr>
									</cfloop>
								</tbody>
							</table>
						</div>
					</div>
				</cfoutput>
				<cfset displayedCount = displayedCount + 1 />
				<cfif displayedCount gte 100>
					<cfbreak />
				</cfif>
			</cfif>
		</cfloop>
	</div>
	<cfoutput>
		<cfif displayedCount eq 0>
			<div class="alert alert-info notFound">
				There are no records to review with the applied filter(s)
			</div>
		<cfelse>
			<div class="alert alert-info notFound">
				Displaying #displayedCount# of #gds.RecordCount# for review
			</div>
		</cfif>
	</cfoutput>
<cfelse>

	<div class="alert alert-info notFound">No GDS records</div>

	<script type="text/javascript" language="javascript">
	<!--
		$(function() {
			$("#filter").show();
		});
	// -->
	</script>
	
</cfif>

<!---
<cfloop index="prop" list="#propList#">
		<cfif IsStruct(compareResult.result[prop])>
			<cfif Len(compareResult.result[prop].string1) gt 0 and Len(compareResult.result[prop].string2) gt 0>
				<cfset totalScore = totalScore + compareResult.result[prop].score />
				<cfset maxScore = maxScore + 1 />
				<cfset pct = compareResult.result[prop].score * 100 />
				<cfset totalMultipliers = totalMultipliers + compareResult.config[prop].multiplier />
				<cfset weightedScore = compareResult.result[prop].score * compareResult.config[prop].multiplier />
				<cfset totalWeightedScore = totalWeightedScore + weightedScore />
				<cfset maxWeightedScore = maxWeightedScore + compareResult.config[prop].multiplier />
				<cfset weightedPCT = weightedScore/compareResult.config[prop].multiplier * 100 />
				<cfset totalOffsets = totalOffsets + compareResult.config[prop].maxOffset />
				<cfset totalLCS = totalLCS + compareResult.result[prop].lcs/>
				<cfset totalDistance = totalDistance + compareResult.result[prop].distance />
				<cfif pct eq 100>
					<cfset perfectScores = perfectScores + 1>
				</cfif>
				<cfset scoreCount = scoreCount + 1 />
				<!--- <cfif compareResult.result[prop].lcs eq 0>
					<cfset lcsDistance = 0 />
				<cfelseif compareResult.result[prop].distance eq 0>
					<cfset lcsDistance = 100 />
				<cfelse>
					<cfset lcsDistance = compareResult.result[prop].lcs/compareResult.result[prop].distance * 100 />
				</cfif> --->
			</cfif>
			<tr>
				<!--- <cfif prop eq ListFirst(propList)>
					<cfset rowspan = ListLen(propList) /> --->
					<td>
						#compareResult.result.first_name.string1# #compareResult.result.last_name.string1#<br />
						#compareResult.result.address.string1#<br />
						#compareResult.result.city.string1#, CA #compareResult.result.zip_code.string1#<br />
						#compareResult.result.email.string1#<br />
						<!--- #compareResult.result.phone1.string1#<br />
						#compareResult.result.phone2.string1#<br /> --->
						#compareResult.result.dob.string1#<br />
						#compareResult.result.ssn.string1#
					</td>
					<td>
						#compareResult.result.first_name.string2# #compareResult.result.last_name.string2#<br />
						#compareResult.result.address.string2#<br />
						#compareResult.result.city.string2#, CA #compareResult.result.zip_code.string2#<br />
						#compareResult.result.email.string2#<br />
						<!--- #compareResult.result.phone1.string2#<br />
						#compareResult.result.phone2.string2#<br /> --->
						#compareResult.result.dob.string2#<br />
						#compareResult.result.ssn.string2#
					</td>
					<td>
						<h2>Score</h2>
						<a href="?action=rejectGDS&view=#view#&GDS_ID=#GDS_ID#" class="btn btn-warning">Unmatch</a>
					</td>
				<!--- </cfif> --->
				<!--- <td>#Round(pct)#%</td> --->
				<cfif showStats>
					<td>
						<table>
							<tr>
								<th class="statcol">Property</th>
								<th class="statcol">Score</th>
								<th class="statcol">Max Offset</th>
								<th class="statcol">LCS</th>
								<th class="statcol">Distance</th>
							</tr>
							<tr>
								<td>#prop#</td>
								<cfif Len(compareResult.result[prop].string1) gt 0 and Len(compareResult.result[prop].string2) gt 0>
									<td>#compareResult.result[prop].score#</td>
									<td>#Int(compareResult.config[prop].maxOffset)#</td>
									<td>#Int(compareResult.result[prop].lcs)#</td>
									<td>#Int(compareResult.result[prop].distance)#</td>
								<cfelse>
									<td colspan="4" style="text-align: center;">N/A</td>
								</cfif>
							</tr>
						</table>
					</td>
				</cfif>
			</tr>
		</cfif>
	</cfloop>

	<!--- <cfset totalPCT = totalScore/maxScore * 100 />
	<cfset totalWeightedPCT = totalWeightedScore/maxWeightedScore * 100 />
	<cfset totalLCSDistance = totalLCS/totalDistance />
	<cfset multiFactorScore = totalPCT * totalLCSDistance />
	<cfif multiFactorScore lt 20>
		<cfset bgColor = "red" />
	<cfelseif multiFactorScore lt 100>
		<cfset bgColor = "orange">
	<cfelse>
		<cfset bgColor = "green" />
	</cfif>
	<cfset perfectScorePCT = perfectScores / scoreCount * 100 />
	<tr style="background-color: #bgColor#; color: white; font-weight: bold;">
		<td colspan="2"></td>
		<td>#DecimalFormat(multiFactorScore)# / #perfectScorePCT#%</td>
		<!--- <td>#Round(totalPCT)#%</td> --->
		<cfif showStats>
			<td></td>
			<td>#Round(totalPCT)#%</td>
			<!--- <td>#totalMultipliers#</td>
			<td>#Round(totalWeightedPCT)#%</td>
			<td>#totalOffsets#</td> --->
			<td>#totalLCS#</td>
			<td>#totalDistance#</td>
			<!--- <td></td> --->
		</cfif>
		
	</tr> --->
				
--->

<!--- <table class="table">
		<thead>
			<tr>
				<th>First Name</th>
				<th>Last Name</th>
				<th>Full Name</th>
				<th>Address</th>
				<th>City</th>
				<th>Zip Code</th>
				<th>Phone 1</th>
				<th>Phone 2</th>
				<th>E-mail</th>
				<th>SSN</th>
				<th>DOB</th>
				<th class="action"></th>
			</tr>
		</thead>
		<tbody> --->
		<!--- <cfset firstNameFactor = 2 />
		<cfset lastNameFactor = 4 />
		<cfset fullNameFactor = 5 />
		<cfset addressFactor = 4 />
		<cfset cityFactor = 2 />
		<cfset zipCodeFactor = 1 />
		<cfset phone1Factor = 5 />
		<cfset phone2Factor = 5 />
		<cfset phoneFactor = 5 />
		<cfset emailFactor = 5 />
		<cfset ssnFactor = 2 />
		<cfset dobFactor = 1 />
		<cfset sumOfFactors = 0 />
		<cfset availableSum = 0 />
		<cfset totalScore = 0 /> --->
					
<!--- old algorithm 
		<cfset gdsFirstName = UCase(REReplace(First_Name, "[^a-zA-Z0-9] ","","all")) />
		<cfset cfcFirstName = UCase(REReplace(Student_First_Name, "[^a-zA-Z0-9] ","","all")) />
		<cfif Len(gdsFirstName) gt 0 and Len(cfcFirstName) gt 0>
			<cfset compFirstName = stringSimilarity(UCase(gdsFirstName), UCase(cfcFirstName), 5) />
			<cfset firstNameSimilarity = compFirstName.similarity />
			<cfset firstNameScore = firstNameSimilarity * firstNameFactor />
			<cfset sumOfFactors = sumOfFactors + firstNameFactor />
		<cfelse>
			<cfset compFirstName = "" />
			<cfset firstNameSimilarity = 0 />
			<cfset firstNameScore = 0 />
		</cfif>
		<cfset totalScore = totalScore + firstNameScore />
		
		<cfset gdsLastName = UCase(REReplace(Last_Name, "[^a-zA-Z0-9 ]","","all")) />
		<cfset cfcLastName = UCase(REReplace(Student_Last_Name, "[^a-zA-Z0-9 ]","","all")) />
		<cfif Len(gdsLastName) gt 0 and Len(cfcLastName) gt 0>
			<cfset compLastName = stringSimilarity(UCase(gdsLastName), UCase(cfcLastName), 5) />
			<cfset lastNameSimilarity = compLastName.similarity />
			<cfset lastNameScore = lastNameSimilarity * lastNameFactor />
			<cfset sumOfFactors = sumOfFactors + lastNameFactor />
		<cfelse>
			<cfset compLastName = "" />
			<cfset lastNameSimilarity = 0 />
			<cfset lastNameScore = 0 />
		</cfif>
		<cfset totalScore = totalScore + lastNameScore />
		
		<cfset gdsFullName = gdsFirstName & gdsLastName />
		<cfset cfcFullName = cfcFirstName & cfcLastName />
		<cfif Len(gdsFirstName) gt 0 and Len(cfcFirstName) gt 0 and Len(gdsLastName) gt 0 and Len(cfcLastName) gt 0>
			<cfset compFullName = stringSimilarity(UCase(gdsFullName), UCase(cfcFullName), 7) />
			<cfset fullNameSimilarity = compFullName.similarity />
			<cfset fullNameScore = fullNameSimilarity * fullNameFactor />
			<cfset sumOfFactors = sumOfFactors + fullNameFactor />
		<cfelse>
			<cfset compFullName = "" />
			<cfset fullNameSimilarity = 0 />
			<cfset fullNameScore = 0 />
		</cfif>
		<cfset totalScore = totalScore + fullNameScore />
		
		<cfset gdsAddress = UCase(REReplace(Address, "[^a-zA-Z0-9 ]","","all")) />
		<cfset cfcAddress = UCase(REReplace(Student_Address, "[^a-zA-Z0-9 ]","","all")) />
		<cfif Len(gdsAddress) gt 0 and Len(cfcAddress) gt 0>
			<cfset compAddress = stringSimilarity(UCase(gdsAddress), UCase(cfcAddress), 6) />
			<cfset addressSimilarity = compAddress.similarity />
			<cfset addressScore = addressSimilarity * addressFactor />
			<cfset sumOfFactors = sumOfFactors + addressFactor />
		<cfelse>
			<cfset compAddress = "" />
			<cfset addressSimilarity = 0 />
			<cfset addressScore = 0 />
		</cfif>
		<cfset totalScore = totalScore + addressScore />
		
		<cfset gdsCity = UCase(REReplace(City, "[^a-zA-Z0-9 ]","","all")) />
		<cfset cfcCity = UCase(REReplace(Student_City, "[^a-zA-Z0-9 ]","","all")) />
		<cfif Len(gdsAddress) gt 0 and Len(cfcAddress) gt 0>
			<cfset compCity = stringSimilarity(UCase(gdsCity), UCase(cfcCity), 5) />
			<cfset citySimilarity = compCity.similarity />
			<cfset cityScore = citySimilarity * cityFactor />
			<cfset sumOfFactors = sumOfFactors + cityFactor />
		<cfelse>
			<cfset compCity = "" />
			<cfset citySimilarity = 0 />
			<cfset cityScore = 0 />
		</cfif>
		<cfset totalScore = totalScore + cityScore />
		
		<cfset gdsZipCode = Right(REReplace(Zip_Code, "[^0-9]","","all"), 5) />
		<cfset cfcZipCode = Right(REReplace(Student_Zip_Code, "[^0-9]","","all"), 5) />
		<cfif Len(gdsZipCode) gt 0 and Len(cfcZipCode) gt 0>
			<cfset compZipCode = stringSimilarity(UCase(gdsZipCode), UCase(cfcZipCode), 1) />
			<cfset zipCodeSimilarity = compZipCode.similarity />
			<cfset zipCodeScore = zipCodeSimilarity * zipCodeFactor />
			<cfset sumOfFactors = sumOfFactors + zipCodeFactor />
		<cfelse>
			<cfset compZipCode = "" />
			<cfset zipCodeSimilarity = 0 />
			<cfset zipCodeScore = 0 />
		</cfif>
		<cfset totalScore = totalScore + zipCodeScore />
		
		<cfset gdsPhone = REReplace(Phone, "[^0-9]","","all") />
		<cfset cfcPhone1 = REReplace(Student_Phone1, "[^0-9]","","all") />
		<cfset cfcPhone2 = REReplace(Student_Phone2, "[^0-9]","","all") />
		<cfif Len(gdsPhone) gt 0 and Len(cfcPhone1) gt 0>
			<cfset compPhone1 = stringSimilarity(gdsPhone, cfcPhone1, 2) />
			<cfset phone1Similarity = compPhone1.similarity />
			<cfset phone1Score = phone1Similarity * phoneFactor />
			<!--- <cfset sumOfFactors = sumOfFactors + phone1Factor /> --->
		<cfelse>
			<cfset compPhone1 = "" />
			<cfset phone1Similarity = 0 />
			<cfset phone1Score = 0 />
		</cfif>
		<!--- <cfset totalScore = totalScore + phone1Score /> --->
		
		<cfif Len(gdsPhone) gt 0 and Len(cfcPhone2) gt 0>
			<cfset compPhone2 = stringSimilarity(gdsPhone, cfcPhone2, 3) />
			<cfset phone2Similarity = compPhone2.similarity />
			<cfset phone2Score = phone2Similarity * phoneFactor />
			<!--- <cfset sumOfFactors = sumOfFactors + phone2Factor /> --->
		<cfelse>
			<cfset compPhone2 = "" />
			<cfset phone2Similarity = 0 />
			<cfset phone2Score = 0 />
		</cfif>
		<!--- <cfset totalScore = totalScore + phone2Score /> --->
		<cfif phone1Score gt phone2Score>
			<cfset phoneSimilarity = phone1Similarity />
			<cfset phoneScore = phone1Score />
			<cfset sumOfFactors = sumOfFactors + phoneFactor />
			<cfset totalScore = totalScore + phone1Score />
		<cfelse>
			<cfset phoneSimilarity = phone2Similarity />
			<cfset phoneScore = phone2Score />
			<cfset sumOfFactors = sumOfFactors + phoneFactor />
			<cfset totalScore = totalScore + phone2Score />
		</cfif>
		
		<cfset gdsEmail = REReplace(Stdt_Email_Addr, "[^a-zA-Z0-9]","","all") />
		<cfset cfcEmail = REReplace(Student_Email, "[^a-zA-Z0-9]","","all") />
		<cfif Len(gdsEmail) gt 0 and Len(cfcEmail) gt 0>
			<cfset compEmail = stringSimilarity(UCase(gdsEmail), UCase(cfcEmail), 5) />
			<cfset emailSimilarity = compEmail.similarity />
			<cfset emailScore = emailSimilarity * emailFactor />
			<cfset sumOfFactors = sumOfFactors + emailFactor />
		<cfelse>
			<cfset compEmail = "" />
			<cfset emailSimilarity = 0 />
			<cfset emailScore = 0 />
		</cfif>
		<cfset totalScore = totalScore + emailScore />
		
		<cfset gdsSSN = Right(REReplace(SSN, "[^a-zA-Z0-9]","","all"), 4) />
		<cfset cfcSSN = Right(REReplace(Student_SSN, "[^a-zA-Z0-9]","","all"), 4) />
		<cfif Len(gdsSSN) gt 0 and Len(cfcSSN) gt 0>
			<cfset compSSN = stringSimilarity(gdsSSN, cfcSSN, 1) />
			<cfset ssnSimilarity = compSSN.similarity />
			<cfset ssnScore = ssnSimilarity * ssnFactor />
			<cfset sumOfFactors = sumOfFactors + ssnFactor />
		<cfelse>
			<cfset compSSN = "" />
			<cfset ssnSimilarity = 0 />
			<cfset ssnScore = 0 />
		</cfif>
		<cfset totalScore = totalScore + ssnScore />
		
		<cfset gdsDOB = DateFormat(DOB, "yyyymmdd") />
		<cfset cfcDOB = DateFormat(Student_DOB, "yyyymmdd") />
		<cfif Len(gdsDOB) gt 0 and Len(cfcDOB) gt 0>
			<cfset compDOB = stringSimilarity(gdsDOB, cfcDOB, 1) />
			<cfset dobSimilarity = compDOB.similarity />
			<cfset dobScore = dobSimilarity * dobFactor />
			<cfset sumOfFactors = sumOfFactors + dobFactor />
		<cfelse>
			<cfset compDOB = "" />
			<cfset dobSimilarity = 0 />
			<cfset dobScore = 0 />
		</cfif>
		<cfset totalScore = totalScore + dobScore />--->
				
<!--- <tr>
		<td width="250">#base.titleCase(First_Name)#</td>
		<td width="250">#base.titleCase(Student_First_Name)#</td>
		<td width="150">#DecimalFormat(firstNameSimilarity)#</td>
		<td width="150">#DecimalFormat(firstNameFactor)#</td>
		<td width="150">#DecimalFormat(firstNameScore)#</td>
	</tr>
	<tr>
		<td>#base.titleCase(Last_Name)#</td>
		<td>#base.titleCase(Student_Last_Name)#</td>
		<td>#DecimalFormat(lastNameSimilarity)#</td>
		<td>#DecimalFormat(lastNameFactor)#</td>
		<td>#DecimalFormat(lastNameScore)#</td>
	</tr>
	<tr>
		<td>#base.titleCase(First_Name)# #base.titleCase(Last_Name)#</td>
		<td>#base.titleCase(Student_First_Name)# #base.titleCase(Student_Last_Name)#</td>
		<td>#DecimalFormat(fullNameSimilarity)#</td>
		<td>#DecimalFormat(fullNameFactor)#</td>
		<td>#DecimalFormat(fullNameScore)#</td>
	</tr>
	<tr>
		<td>#base.titleCase(Address)#</td>
		<td>#base.titleCase(Student_Address)#</td>
		<td>#DecimalFormat(addressSimilarity)#</td>
		<td>#DecimalFormat(addressFactor)#</td>
		<td>#DecimalFormat(addressScore)#</td>
	</tr>
	<tr>
		<td>#base.titleCase(City)#</td>
		<td>#base.titleCase(Student_City)#</td>
		<td>#DecimalFormat(citySimilarity)#</td>
		<td>#DecimalFormat(cityFactor)#</td>
		<td>#DecimalFormat(cityScore)#</td>
	</tr>
	<tr>
		<td>#Zip_Code#</td>
		<td>#Student_Zip_Code#</td>
		<td>#DecimalFormat(zipCodeSimilarity)#</td>
		<td>#DecimalFormat(zipCodeFactor)#</td>
		<td>#DecimalFormat(zipCodeScore)#</td>
	</tr>
	
	<tr>
		<td>#base.formatPhone(Phone)#</td>
		<td>
		<cfif phone1Score gt phone2Score>
			#base.formatPhone(Student_Phone1)#
		<cfelse>
			#base.formatPhone(Student_Phone2)#
		</cfif>
		</td>
		<td>#DecimalFormat(phoneSimilarity)#</td>
		<td>#DecimalFormat(phoneFactor)#</td>
		<td>#DecimalFormat(phoneScore)#</td>
	</tr>
	<tr>
		<td>#LCase(Stdt_Email_Addr)#</td>
		<td>#LCase(Student_Email)#</td>
		<td>#DecimalFormat(emailSimilarity)#</td>
		<td>#DecimalFormat(emailFactor)#</td>
		<td>#DecimalFormat(emailScore)#</td>
	</tr>
	<tr>
		<td>#SSN#</td>
		<td>#Student_SSN#</td>
		<td>#DecimalFormat(ssnSimilarity)#</td>
		<td>#DecimalFormat(ssnFactor)#</td>
		<td>#DecimalFormat(ssnScore)#</td>
	</tr>
	<tr>
		<td>#DateFormat(DOB, "m/d/yyyy")#</td>
		<td>#DateFormat(Student_DOB, "m/d/yyyy")#</td>
		<td>#DecimalFormat(dobSimilarity)#</td>
		<td>#DecimalFormat(dobFactor)#</td>
		<td>#DecimalFormat(dobScore)#</td>
	</tr> --->
								
								
<!--- <script type="text/javascript">
		
		var parseQuestions = function(questions) {
			for (var q = 0; q < questions.length; q++) {
				questions[q].QUESTION_NUMBER = parseInt(questions[q].QUESTION_NUMBER);
				questions[q].RESPONSE_COUNT = parseInt(questions[q].RESPONSE_COUNT);
				questions[q].MULTI_RESPONSE_COUNT = parseInt(questions[q].MULTI_RESPONSE_COUNT);
				questions[q].NO_RESPONSE_COUNT = parseInt(questions[q].NO_RESPONSE_COUNT);
			}
			return questions;
		}
		
		var parseAnswers = function(answers) {
			for (var a = 0; a < answers.length; a++) {
				if (answers[a].ANSWER === true) {
					answers[a].ANSWER = "Yes ";
				} else if (answers[a].ANSWER === false) {
					answers[a].ANSWER = "No ";
				}
				answers[a].ANSWER_NUMBER = parseInt(answers[a].ANSWER_NUMBER);

				answers[a].RESPONSE_COUNT = parseInt(answers[a].RESPONSE_COUNT);
				answers[a].RESPONSE_PERCENT = parseFloat(answers[a].RESPONSE_PERCENT);
				//answers[a].RESPONSE_OTHER = answers[a].ANSWER_VALUES.toString();
				answers[a].EXPLODE = false;
			}
			return answers;
		}

		<cfoutput>
			var questions = #SerializeJSON(evaluations)#;
		</cfoutput>
		
		var pieLabelTemplate = "#= dataItem.ANSWER# - #= dataItem.RESPONSE_PERCENT#%";
		var pieLegendTemplate = "#= dataItem.ANSWER# - #= dataItem.RESPONSE_PERCENT#%";
		//var pieTooltipTemplate = "#= dataItem.ANSWER# - #= dataItem.RESPONSE_COUNT#";
		var pieTooltipTemplate = "#= dataItem.RESPONSE_COUNT# responses = #= dataItem.RESPONSE_PERCENT#%";
		var barLabelTemplate = "#= dataItem.ANSWER# - #= dataItem.RESPONSE_PERCENT#%";
		var barLegendTemplate = "#= text#";
		var barTooltipTemplate = "#= dataItem.RESPONSE_COUNT# responses = #= dataItem.RESPONSE_PERCENT#%";
		var labelFont = "12px Arial,Helvetical,sans-serif";
		var legendFont = "12px Arial,Helvetical,sans-serif";
		var tooltipFont = "12px Arial,Helvetical,sans-serif";
		
		renderPieChart = function(q) {
			var question = questions[q-1];
			var answers = parseAnswers(question.ANSWERS);
			$("#q" + q + "Chart").kendoChart({
				theme: $(document).data("kendoSkin") || "metro",
				dataSource: answers,
				series: [{
					type: "pie",
					field: "RESPONSE_PERCENT",
					categoryField: "ANSWER",
					explodeField: "EXPLODE",
					labels: {
						visible: true,
						align: "circle",
						font: labelFont,
						template: pieLabelTemplate,
						distance: 20
					},
					padding: 50
				}],
				legend: {
					visible: false,
					position: "left",
					labels: {
						font: legendFont,
						template: pieLegendTemplate
					}
				},
				tooltip: {
					visible: true,
					font: tooltipFont,
					template: pieTooltipTemplate
				}
			})
		}
		
		renderBarChart = function(q) {
			var question = questions[q-1];
			var answers = parseAnswers(question.ANSWERS);
			$("#q" + q + "Chart").kendoChart({
				theme: $(document).data("kendoSkin") || "metro",
				dataSource: answers,
				plotArea: {
					margin: {
						right: 200
					}
				},
				series: [{
					type: "bar",
					field: "RESPONSE_PERCENT",
					categoryField: "ANSWER",
					labels: {visible: true, font: labelFont, template: barLabelTemplate, position: "outsideEnd"},
					missingValue: "zero",
					gap: 0.4,
					spacing: 0.2,
					markers: {visible: true, border: {width: 2, size: 6}},
					padding: 50
				}],
				valueAxis: {
					title: {visible: false, text: "valueAxis"},
					labels: {template: "#= value#%"},
					majorGridLines: {visible: true, color: "gray"},
					majorTicks: {visible: true, color: "gray"},
					minorGridLines: {visible: false, color: "silver"},
					minorTicks: {visible: false, color: "silver"},
					plotBands: [{
						from: 49,
						to: 51,
						color: "gray",
						opacity: 0.3
					}]
				},
				categoryAxis: {
					title: {visible: false, text: "categoryAxis"},
					majorGridLines: {visible: false},
					majorTicks: {visible: false}
				},
				legend: {
					visible: false,
					position: "left",
					labels: {font: legendFont, template: barLegendTemplate}
				},
				tooltip: {
					visible: true,
					font: tooltipFont,
					template: barTooltipTemplate
				}
			})
		}

		$(function() {
			var pieCharts = "1,2,3,4,5,7,10,11,13,15,17,19";
			var barCharts = "6,9,12,14,16,18";
			var pieChartsArray = pieCharts.split(",");
			var barChartsArray = barCharts.split(",");
			if (pieChartsArray.length > 0) {
				for (var q = 0; q < pieChartsArray.length; q++) {
					renderPieChart(pieChartsArray[q]);
				}
			}
			if (barChartsArray.length > 0) {
				for (var q = 0; q < barChartsArray.length; q++) {
					renderBarChart(barChartsArray[q]);
				}
			}
		})
	
	</script>
	<style type="text/css">
		.k-chart {
			width: 800px;
			height: 400px;
		}
	</style>

	<cfoutput>

		<div class="accordion" id="esAccordian">

			<cfloop index="q" from="1" to="#ArrayLen(evaluations)#">
				<cfset totalExitSurveys = evaluations[q].Response_Count + evaluations[q].No_Response_Count />
				<cfset noResponsePercent = evaluations[q].No_Response_Count / totalExitSurveys * 100 />
				<cfset multiResponsePercent = evaluations[q].Multi_Response_Count / totalExitSurveys * 100 />
				<div class="accordion-group">
					<div class="accordion-heading"> <a class="accordion-toggle" data-toggle="collapse" data-parent="##esAccordian" href="##p#q#">#q#. #evaluations[q].Question#</a> </div>
					<div id="p#q#" class="accordion-body collapse<cfif q eq 1> in</cfif>">
						<div class="accordion-inner">
							<cfif q eq 8>
								Data can not be charted. 
							<cfelse>
								<ul class="nav nav-pills">
									<li class="active"><a href="##table#q#" data-toggle="pill">Table</a></li>
									<li><a href="##chart#q#" data-toggle="pill">Chart</a></li>
								</ul>
								<div class="tab-content">
									<div class="tab-pane active" id="table#q#">
										<table class="table table-hover table-bordered">
											<thead>
												<th>Answer</th>
												<th>Count</th>
												<th>Percent</th>
											</thead>
											<tbody>
												<cfloop index="a" from="1" to="#ArrayLen(evaluations[q].Answers)#">
													<tr>
														<td>#evaluations[q].Answers[a].Answer#</td>
														<td>#evaluations[q].Answers[a].Response_Count#</td>
														<td>#evaluations[q].Answers[a].Response_Percent#%</td>
													</tr>
												</cfloop>
												<tr>
													<td>Did not respond</td>
													<td>#evaluations[q].No_Response_Count#</td>
													<td>#DecimalFormat(noResponsePercent)#%</td>
												</tr>
												<cfif evaluations[q].Question_Type eq "Multiple select">
													<tr>
														<td>Multiple responses</td>
														<td>#evaluations[q].Multi_Response_Count#</td>
														<td>#DecimalFormat(multiResponsePercent)#%</td>
													</tr>
												</cfif>
											</tbody>
										</table>
									</div>
									<div class="tab-pane" id="chart#q#">
										<div id="q#q#Chart"></div>
									</div>
								</div>
							</cfif>
						</div>
					</div>
				</div>
			</cfloop>
		</div>
	
	</cfoutput> --->
<!--- <tr>
	<td colspan="12">
	
		<table>
			<tr>
				<td width="50%">
					#base.titleCase(First_Name)# #base.titleCase(Last_Name)#<br />
					#base.titleCase(Address)#<br />
					#base.titleCase(City)#, CA #Zip_Code#<br />
					#base.formatPhone(Phone)#<br />
					#LCase(Stdt_Email_Addr)#<br />
					#SSN#<br />
					#DateFormat(DOB, "m/d/yyyy")#
				</td>
				<td width="50%">
					#base.titleCase(Student_First_Name)# #base.titleCase(Student_Last_Name)#<br />
					#base.titleCase(Student_Address)#<br />
					#base.titleCase(Student_City)#, CA #Student_Zip_Code#<br />
					<cfif Len(Trim(Student_Phone2)) gt 0 and compPhone2.similarity gt compPhone1.similarity>
						#base.formatPhone(Student_Phone2)#<br />
					<cfelseif Len(Trim(Student_Phone1)) gt 0>
						#base.formatPhone(Student_Phone1)#<br />
					</cfif>
					#LCase(Student_Email)#<br />
					#Student_SSN#<br />
					#DateFormat(Student_DOB, "m/d/yyyy")#
				</td>
			</tr>
		</table>
		
	</td>
</tr>	
<tr>
	<td>#base.titleCase(First_Name)#</td>
	<td>#base.titleCase(Last_Name)#</td>
	<td>#base.titleCase(First_Name)# #base.titleCase(Last_Name)#</td>
	<td>#base.titleCase(Address)#</td>
	<td>#base.titleCase(City)#</td>
	<td>#Zip_Code#</td>
	<td>#base.formatPhone(Phone)#</td>
	<td>#base.formatPhone(Phone)#</td>
	<td>#LCase(Stdt_Email_Addr)#</td>
	<td>#SSN#</td>
	<td>#DateFormat(DOB, "m/d/yyyy")#</td>
	<td></td>
</tr>
<tr>
	<td>#base.titleCase(Student_First_Name)#</td>
	<td>#base.titleCase(Student_Last_Name)#</td>
	<td>#base.titleCase(Student_First_Name)# #base.titleCase(Student_Last_Name)#</td>
	<td>#base.titleCase(Student_Address)#</td>
	<td>#base.titleCase(Student_City)#</td>
	<td>#Student_Zip_Code#</td>
	<td>#base.formatPhone(Student_Phone1)#</td>
	<td>#base.formatPhone(Student_Phone2)#</td>
	<td>#LCase(Student_Email)#</td>
	<td>#Student_SSN#</td>
	<td>#DateFormat(Student_DOB, "m/d/yyyy")#</td>
	<td></td>
</tr>
<tr>
	<td>#DecimalFormat(compFirstName.similarity)#</td>
	<td>#DecimalFormat(compLastName.similarity)#</td>
	<td>#DecimalFormat(compFullName.similarity)#</td>
	<td>#DecimalFormat(compAddress.similarity)#</td>
	<td>#DecimalFormat(compCity.similarity)#</td>
	<td>#DecimalFormat(compZipCode.similarity)#</td>
	<td>#DecimalFormat(compPhone1.similarity)#</td>
	<td>#DecimalFormat(compPhone2.similarity)#</td>
	<td>#DecimalFormat(compEmail.similarity)#</td>
	<td>#DecimalFormat(compSSN.similarity)#</td>
	<td>#DecimalFormat(compDOB.similarity)#</td>
	<td></td>
</tr>
 --->